USE [bmig_Mensual_Post_cadena]
GO

IF EXISTS (SELECT name FROM   sysobjects WHERE  name = N'[dbo].[WASP_M0014_CODIGOS_SEGUROS]' AND type = 'P')
    DROP PROCEDURE [dbo].[WASP_M0014_CODIGOS_SEGUROS]
GO

CREATE PROCEDURE [dbo].[WASP_M0014_CODIGOS_SEGUROS]

AS


BEGIN
SELECT a.ppcta, a.ppoper, a.ppsuc, 
       a.ppimp11, a.ppimp12, a.ppimp13, a.ppimp14, a.ppimp15,
       a.ppimp16, a.ppimp17, a.ppimp18, a.ppimp19

INTO dbo.sc_codseg

FROM  fsd611 as a (nolock),
      fsd601 as b  (nolock)

WHERE 
      a.pptipo = '' and a.ppexte = 9 and
      a.pgcod = b.pgcod and
      a.ppmod = b.ppmod and
      a.ppsuc = b.ppsuc and 
      a.ppmda = b.ppmda and
      a.ppcta = b.ppcta and 
      a.ppoper = b.ppoper and
      a.ppsbop = b.ppsbop and
      a.pptope = b.pptope and
      b.d601co = 'S'

GROUP BY a.ppsuc, a.ppcta, a.ppoper, a.ppimp11, a.ppimp12,
         a.ppimp13, a.ppimp14, a.ppimp15, a.ppimp16,
         a.ppimp17, a.ppimp18, a.ppimp19
         
END
